package nc.ui.arap.buttonstat;

import java.util.Vector;

import nc.ui.arap.engine.AbstractRuntime;
import nc.ui.arap.engine.ExtButtonObject;
import nc.ui.arap.engine.IActionRuntime;
import nc.ui.arap.engine.IButtonStatus;
import nc.ui.arap.global.DjTempletHelper;
import nc.ui.ep.dj.ArapBillWorkPageConst;
import nc.vo.ep.dj.DJZBHeaderVO;
import nc.vo.ep.dj.DJZBVO;
import nc.vo.ep.dj.DJZBVOConsts;

public class DjSsUnCloseStatLinsener implements IButtonStatus {

	public void updateButtonStatus(ExtButtonObject bo, IActionRuntime runtime) {
		// TODO Auto-generated method stub
		if(!(runtime instanceof AbstractRuntime))
			return ;
		AbstractRuntime runt=(AbstractRuntime)runtime;
		bo.setEnabled(false);
		if(runt.getCurrWorkPage()==ArapBillWorkPageConst.CARDPAGE){
			DJZBVO djvo = runt.getDjDataBuffer().getCurrentDJZBVO();
			if (djvo != null) {
				DJZBHeaderVO head = (DJZBHeaderVO) djvo.getParentVO();
				if (head != null) {
					if (head.getDjzt().intValue() == DJZBVOConsts.m_intDJStatus_Closed) {
						bo.setEnabled(true);
						bo.setVisible(true);
					}
				}
			}
		}else{
			if (DjTempletHelper.isListSelectedBill(runt)) {
				if (DjTempletHelper.isListSelectedBill(runt)) {
					if (runt.getDjDataBuffer().getCurrentDJZBVO()!=null && ((DJZBHeaderVO) runt.getDjDataBuffer().getCurrentDJZBVO()
							.getParentVO()).getDjzt().intValue() == DJZBVOConsts.m_intDJStatus_Closed) {
						bo.setEnabled(true);
						bo.setVisible(true);
					}else{
						Vector<String> pkLs = DjTempletHelper.getAllSelectedDJPK(runt);
						if(pkLs != null && pkLs.size() > 0){
							if(runt.getDjDataBuffer().getDJZBVO(pkLs.get(0))!=null && ((DJZBHeaderVO) runt.getDjDataBuffer().getDJZBVO(pkLs.get(0))
									.getParentVO()).getDjzt().intValue() == DJZBVOConsts.m_intDJStatus_Closed){
								bo.setEnabled(true);
								bo.setVisible(true);
							}
						}
					}
				}
			}
		}
	}

}
